// pages/student/rechargeable/rechargeable.js
const app = getApp()
var CONFIG = require("../../../config/config.js");
var share = require('../../../utils/share.js');
Page({

    /**
     * 页面的初始数据
     */
    data: {
        phone: '',
        dataList: '',
        dataList2: '',
        msg: '',
        page: 0,
        indextab: 1,
        card_money: '',
    },

    moneyclick(){
        var that = this;
        wx.navigateTo({
            url: '/pages/student/rechargeable/rechargemoney?phone='+that.data.phone+'',
        })
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var that = this;
        var phone = wx.getStorageSync('tel');
        that.setData({
            phone: phone
        })
        that.cardMoneyLog(1);
    },
    onShow(){
        var that = this;
        that.cardMoneyLog(1);
    },

    // 充值记录
    moneyLog() {
        var that = this;
        that.setData({
            indextab: 1,
            dataList: [],
            page: 0,
            msg: '',
        })
        that.cardMoneyLog(1);
    },
    // 消费记录
    moneyLog1() {
        var that = this;
        that.setData({
            indextab: 2,
            dataList: [],
            page: 0,
            msg: '',
        })
        that.cardMoneyLog(2);
    },

    cardMoneyLog(type) {
        var that = this;
        wx.showLoading({
            title: '加载中~',
        })
        var phone = wx.getStorageSync('tel');
        var page = that.data.page;
        
        share.wxRequest('crmapi/Student/cardMoneyLog', { phone: phone,type:type }, function (res) {
            if (Number(res.data.errcode) == 0) {
                var data = res.data.data;
                that.setData({
                    card_money: res.data.card_money
                })
                if (Number(page) == 0) {
                    if (data&&Number(data.length) != 0) {
                        that.setData({
                            dataList: data
                        })
                    } else {
                        if (Number(type) == 1) {
                            var msg = '暂无个人卡充值记录'
                        } else {
                            var msg = '暂无个人卡消费记录'
                        }
                        that.setData({
                            msg: msg
                        })
                    }
                } else {
                    var data1 = that.data.dataList;
                    that.setData({
                        dataList: data1.concat(data.res)
                    })
                }

            } else {
                that.setData({
                    msg: res.data.msg
                })
            }
            wx.hideLoading();
        })
    },



    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
        // console.log(8989)
        var that = this;
        var page = that.data.page;
        page++;
        that.setData({
            page: page
        })
        that.cardMoneyLog(that.data.indextab);
    },

})